#include <LDIR.RSG>
#include "ProgressNote.h"

CProgressNote::~CProgressNote()
    {
    if ( iProgressDialog )
        {
        TRAPD(err, iProgressDialog->ProcessFinishedL());
        delete iProgressDialog;
        }

    if ( iWaitDialog )
        {
        TRAPD(err, iWaitDialog->ProcessFinishedL());
        delete iWaitDialog;
        }
    }

CProgressNote* CProgressNote::NewL()
    {
    CProgressNote* me = new ( ELeave ) CProgressNote;
    return me;
    }

void CProgressNote::StartWaitNoteL( const TDesC& aText )
    {
    iWaitDialog = new ( ELeave ) CAknWaitDialog(
        ( REINTERPRET_CAST(CEikDialog**, &iWaitDialog) ), ETrue );
    iWaitDialog->PrepareLC( R_WAIT_NOTE_SOFTKEY_CANCEL );
    iWaitDialog->SetCallback( this );
    iWaitDialog->SetTextL( aText );
    iWaitDialog->RunLD();
    }

void CProgressNote::StartProgressNoteL( TInt aFinalValue )
    {
    iProgressDialog = new ( ELeave ) CAknProgressDialog(
        ( REINTERPRET_CAST(CEikDialog**, &iProgressDialog) ), ETrue );
    iProgressDialog->PrepareLC( R_PROGRESS_NOTE );
    iProgressInfo = iProgressDialog->GetProgressInfoL();
    iProgressDialog->SetCallback( this );
    iProgressDialog->RunLD();
    iProgressInfo->SetFinalValue( aFinalValue );
    }

void CProgressNote::UpdateProcessL( TInt aProgress, const TDesC& aProgressText )
    {
    if ( iProgressDialog )
        {
        iProgressDialog->SetTextL( aProgressText );
        }

    if ( iProgressInfo )
        {
        iProgressInfo->SetAndDraw( aProgress );
        }
    }

void CProgressNote::DialogDismissedL( TInt aButtonId )
    {
    iProgressDialog = NULL;
    iProgressInfo = NULL;
    iWaitDialog = NULL;

    if ( aButtonId == EAknSoftkeyCancel )
        {
        // cancel any process in here
        DismissedByUser();
        }
    }
